﻿package mortal.game.manager.msgTip
{
    import com.gengine.core.frame.*;
    import com.gengine.global.*;
    import com.gengine.utils.pools.*;
    import flash.display.*;
    import mortal.game.manager.*;
    import mortal.game.view.msgbroad.*;
    import mortal.mvc.interfaces.*;

    public class MsgBroadCastImpl extends Sprite
    {
        private var _needRedraw:Boolean;
        private var _timer:FrameTimer;
        private var _pushing:Boolean;
        private var _inDis:int = 70;
        private var _gad:int = 0;
        private var _layer:ILayer;

        public function MsgBroadCastImpl()
        {
            this.layer = LayerManager.msgTipLayer;
            mouseEnabled = false;
            mouseChildren = false;
            var _loc_1:* = new Sprite();
            _loc_1.graphics.lineStyle(2, 16711680, 1);
            _loc_1.graphics.beginFill(16711680, 1);
            _loc_1.graphics.drawRect(0, 0, this.width, this.height + this._inDis);
            _loc_1.graphics.endFill();
            addChild(_loc_1);
            this.mask = _loc_1;
            this.cacheAsBitmap = true;
            this._timer = new FrameTimer();
            this._timer.addListener(TimerType.ENTERFRAME, this.onEnterFrame);
            this._timer.start();
            return;
        }// end function

        public function set layer(param1:ILayer) : void
        {
            this._layer = param1;
            this._layer.addPopUp(this);
            return;
        }// end function

        private function onNoticeHide(param1:NoticeItem) : void
        {
            if (param1.parent)
            {
                removeChild(param1);
            }
            param1.dispose();
            ObjectPool.disposeObject(param1, NoticeItem);
            return;
        }// end function

        private function onLastItemHide(param1:NoticeItem) : void
        {
            if (contains(param1))
            {
                removeChild(param1);
            }
            param1.dispose();
            ObjectPool.disposeObject(param1, NoticeItem);
            return;
        }// end function

        public function showNotice(param1:String) : void
        {
            var _loc_2:Boolean = false;
            var _loc_3:NoticeItem = null;
            var _loc_4:NoticeItem = null;
            if (!param1 || param1 == "")
            {
                return;
            }
            if (this._layer)
            {
                this._layer.setTop(this);
            }
            if (numChildren > 1)
            {
                if (numChildren >= 4)
                {
                    this._pushing = true;
                    _loc_4 = getChildAt(1) as NoticeItem;
                    _loc_4.easeHide(this.onLastItemHide);
                    this._pushing = false;
                }
                (getChildAt((numChildren - 1)) as NoticeItem).killInEase();
                _loc_2 = false;
            }
            else
            {
                _loc_2 = false;
            }
            _loc_3 = ObjectPool.getObject(NoticeItem);
            addChild(_loc_3);
            _loc_3.updateData(param1, this.onNoticeHide, this._inDis, _loc_2);
            this._needRedraw = true;
            return;
        }// end function

        private function onEnterFrame(param1:FrameTimer) : void
        {
            if (this._needRedraw && !this._pushing)
            {
                this._needRedraw = false;
                this.updatePxy();
            }
            return;
        }// end function

        public function updatePxy() : void
        {
            var _loc_2:int = 0;
            var _loc_3:NoticeItem = null;
            var _loc_4:int = 0;
            var _loc_1:int = 0;
            _loc_2 = numChildren - 1;
            while (_loc_2 > _loc_1)
            {
                
                _loc_3 = getChildAt(_loc_2) as NoticeItem;
                if (_loc_3.hideIng)
                {
                    _loc_2 = _loc_2 - 1;
                    continue;
                }
                if (_loc_3.disposed)
                {
                    if (_loc_3.parent)
                    {
                        removeChild(_loc_3);
                    }
                    _loc_2 = _loc_2 - 1;
                    continue;
                }
                _loc_3.x = (this.width - _loc_3.width) / 2;
                if (_loc_2 != (numChildren - 1))
                {
                    _loc_3.updatePosY(this.height - _loc_3.height - _loc_4);
                }
                else
                {
                    _loc_3.updatePosY(this.height - _loc_3.height - _loc_4);
                }
                _loc_4 = _loc_4 + _loc_3.height;
                _loc_4 = _loc_4 + this._gad;
                _loc_2 = _loc_2 - 1;
            }
            return;
        }// end function

        public function stageResize() : void
        {
            x = (Global.stage.stageWidth - this.width) / 2;
            y = 85;
            return;
        }// end function

        override public function get height() : Number
        {
            return 60;
        }// end function

        override public function get width() : Number
        {
            return 810;
        }// end function

    }
}
